package training.minggu5.maven.ui.barang;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import training.minggu5.maven.service.BarangService;


public class DeleteBarang extends HttpServlet {

    private BarangService barvice;

    @Override
    public void init(ServletConfig config) throws ServletException {
	ApplicationContext ctx = WebApplicationContextUtils
		.getWebApplicationContext(config.getServletContext());

	barvice = (BarangService) ctx.getBean("barangService");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        barvice.deleteBarang(barvice.findBarangByKode(req.getParameter("k")));
        resp.sendRedirect("muka");
    }

}
